package com.jic.veteran.common.leaf;

import com.alibaba.druid.pool.DruidDataSource;
import com.jic.veteran.common.leaf.common.PropertyFactory;
import com.jic.veteran.common.leaf.common.Result;
import com.jic.veteran.common.leaf.snowflake.SnowflakeIDGenImpl;

import java.util.Properties;

public class LeafSnowflakeIdBuilder {
    private static final Properties properties;
    DruidDataSource dataSource;

    static {
        properties = PropertyFactory.getProperties();
    }

    private static class InstanceHolder {
        private final static LeafSnowflakeIdBuilder instance = new LeafSnowflakeIdBuilder();
    }

    public static LeafSnowflakeIdBuilder getInstance() {
        return InstanceHolder.instance;
    }
    public String generateId(String key) {
        Properties properties = PropertyFactory.getProperties();
        IDGen idGen = new SnowflakeIDGenImpl(properties.getProperty("leaf.zk.list"), 2181);
        Result r = idGen.get("qdrjq");
        System.out.println(r);
        String result = String.valueOf(r.getId());
        return result;
    }

    public static void main(String[] args) {
        LeafSnowflakeIdBuilder.getInstance().generateId("zjkccbopen");
    }
}
